<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">

<title>乙秒购</title>

<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link rel="stylesheet" href="./css/conmon.css">
</head>

<body>
	<header>
		<div class="welcome">
			<span>欢迎登陆乙秒购管理平台</span>
		</div>
	</header>
	<section>

		<div class="sign">
			<div class="title">乙秒购管理平台</div>
			<div class="sign_in">
				<ul class="userChoose">
					<!-- <li value="0">总部</li>
					<li value="1">代理</li>
					<li value="2">异业</li> -->
					<li value="3">超市</li>
				</ul>
				<div class="form" id="savehistory">
					<!--    <form  action="" method="post">-->
					<input type="text" id="typeID" style="display: none">
					<div class="username">
						<input maxlength="20" type="text" name="username" id="user"
							placeholder="请输入账户名">
					</div>
					<div class="password">
						<input maxlength="20" type="password" name="password"
							id="password" placeholder="请输入密码">
					</div>
					<div class="verification">
						<div class="verification_pic">
							<canvas class="J_codeimg" id="myCanvas" style="color: #FFFFFF"
								onclick="createCode()"></canvas>
						</div>
						<div class="verification_input">
							<input maxlength="4" name="" id="inputCode" type="text"
								placeholder="请输入右侧验证码" />
						</div>



					</div>
					<button onclick="login();" class="btn">登&nbsp; &nbsp;
						&nbsp; 陆</button>
					<div class="remember">
						<div class="rp">
							<input id="check" type="checkbox"><span> &nbsp;
								记住密码？</span>
						</div>
						<div class="forgot">
							<span> <a href="">&nbsp; &nbsp;
									&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;忘记密码</a></span>
						</div>

					</div>
					<!--    </form>-->
				</div>
			</div>
		</div>

	</section>
	<footer>
		<div class="info">
			<h4>乙秒购&nbsp; 版权所有</h4>
		</div>
	</footer>
	<script src="./js/jquery.min.js"></script>
    <script src="./js/MD5.js"></script>
     <script src="./js/main.js"></script>
	<script type="text/javascript">
		$(function() {
			createCode();
			$(".userChoose>li").click(function() {
				$("#typeID").val($(this).attr("value"));
				$(this).css({
					"background-color" : "#f4f5ff",
					"color" : "#191a19"
				});
				$(this).siblings("li").css({
					"background-color" : "transparent",
					"color" : "#E8F2EF"
				})
			});
			init1();
		});
		var code; //在全局 定义验证码
	
		function createCode() {
			code = "";
			var codeLength = 4; //验证码的长度
			var selectChar = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
	
			for (var i = 0; i < codeLength; i++) {
				var charIndex = Math.floor(Math.random() * 60);
				code += selectChar[charIndex];
			}
			if (code.length != codeLength) {
				createCode();
			}
			showCheck(code);
	
		}
	
		//验证码
		function showCheck(a) { /* 显示验证码图片 */
			var c = document.getElementById("myCanvas");
			var ctx = c.getContext("2d");
			ctx.fillStyle = "#fffefa";
			ctx.clearRect(0, 0, 1000, 1000);
			ctx.font = "80px Arial";
			ctx.fillText(a, 0, 100);
	
		}
	
	
	
		// 注册保存密码localStorage
		function init1() {
			var booleans = localStorage.getItem("config");
			var index = localStorage.getItem("typeID");
			if (booleans == "false") {
				document.getElementById("check").checked = false;
			} else {
				document.getElementById("check").checked = true;
				document.getElementById("password").value = localStorage.getItem("password");
			}
			document.getElementById("user").value = localStorage.getItem("user");
			document.getElementById("typeID").value = localStorage.getItem("typeID");
			if (!index == "") {
				$(".userChoose>li").eq(index).css({
					"background-color" : "#f4f5ff",
					"color" : "#191a19"
				});
				$(".userChoose>li").eq(index).siblings("li").css({
					"background-color" : "transparent",
					"color" : "#E8F2EF"
				})
			}
	
		}
		//登录
	
		function login() {
			var codeInput = document.getElementById("inputCode").value;
			saveLocal();
			//if (codeInput.toLowerCase() == code.toLowerCase()) {
				var userName = document.getElementById("user").value;
				var passWord = document.getElementById("password").value;
				var typeID = 3;
				$.post(urls+"superMarketAction/login.action",
					{
						username : userName,
						password : $.md5(passWord),
						typeID : 3,
					},
					function(data) {
						//console.log(data)
						if(data==250){
						 alert("账号异常，请联系总部")
						}
						else if(data){
							if (typeID == 0) {
							    localStorage.setItem("headid",data.id);
								localStorage.setItem("headname", data.agentName);
								localStorage.setItem("headprincipal",data.principal);
								localStorage.setItem("headaddress", data.agentRegion);
								location.href = "YMGback/head/headIndex.jsp";
	
							} else if (typeID == 1) {
							//location.href = "YMGback/agent/prodcutList.jsp";
							    localStorage.setItem("agentid",data.id);
								localStorage.setItem("agentname", data.agentName);
								localStorage.setItem("agentprincipal",data.principal);
								localStorage.setItem("agentaddress", data.agentRegion);
								//location.href = "YMGback/super/chaoshi.jsp";
							    location.href = "YMGback/agent/productList.jsp";
							} else if (typeID == 2) {
							  localStorage.setItem("otherid",data.id);
								localStorage.setItem("othername", data.otherName);
								localStorage.setItem("otherprincipal",data.otherPrincipal);
								localStorage.setItem("otheraddress", data.otherAdd);
								location.href = "YMGback/other/otherIndex.jsp";
							} else if (typeID == 3) {
								localStorage.setItem("id",data.id);
								localStorage.setItem("name", data.name);
								localStorage.setItem("principal",data.principal);
								localStorage.setItem("address", data.address);
								localStorage.setItem("superstatus", data.status);
								localStorage.setItem("superphone", data.phone);
								location.href = "YMGback/super/chaoshi.jsp";
	
							}
						} else {
							alert("账号密码错误");
						}
					});
	
			//} else {
				//alert("输入的验证码错误")
			//}
		}
		function saveLocal() {
			localStorage.setItem("user", document.getElementById("user").value);
			localStorage.setItem("password", document.getElementById("password").value);
			localStorage.setItem("config", document.getElementById("check").checked);
			localStorage.setItem("typeID", document.getElementById("typeID").value);	
		}
		$("body").keydown(function() {
             if (event.keyCode == "13") {//keyCode=13是回车键
                 login();
             }
         });
	</script>
</body>
</html>
